package calorie.com.calorie.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.ModifyDealPwdRequest;
import calorie.com.calorie.request.SendCodeRequest;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;

public class ModifyDealPwdContact {
    public static class ModifyDealPwdPresent extends BasePresent<IModifyDealPwd> {
        public void modifyDealPwd(Context context,String phone, String password, String code) {
            ApiService service = ServiceGenerator.createService(ApiService.class);
            int userId = SPUtils.getInt(Constant.USER_ID, -1, context);
            ModifyDealPwdRequest request=new ModifyDealPwdRequest(phone, Md5Utils.stringToMD5(password),code,userId);
            service.updateDealPassword(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getUpdatePassword(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }

        public void sendCode(Context context,String phone) {
            ApiService service = ServiceGenerator.createService(ApiService.class);
            String account = SPUtils.getString(Constant.ACCOUNT, null, context);
            service.sendCode(new SendCodeRequest(phone, account, "3")).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getSendCodeResult(response);
                    }
                }

                @Override
                public void onFailed() {
                    //ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }

    }


    public interface IModifyDealPwd extends IBaseView {
        void getUpdatePassword(Response<ResultDTO> resultDTOResponse);

        void getSendCodeResult(Response<ResultDTO> resultDTOResponse);
    }
}
